import main_menu from '../../../main_menu'
import {Swiper, Slide} from 'vue-swiper-component';

var that
var interval_obj=null
export default {
    data() {
        return this.datainit({
            code:null,
            group: null,
            golist: [],
            goods_list:[],
            time:Date.parse(new Date())/1000,
            tab:0
        })
    },
    components: {main_menu, Swiper, Slide},

    mounted: function () {
        that = this
        this.check()
        interval_obj=setInterval(function () {
            that.setendtime();

        },1000)
    },
    beforeDestroy:function(){
        clearInterval(interval_obj)
    },
    methods: {
        user_init: function (_user) {
            let _code = this.$route.query.group_code
            that.code=_code
            that.$post("api/group/get", {code: that.code}, function (data) {
                if(data==null){
                    that.$toast("您还没有加入任何群主")
                }
                that.group=data
            })
            that.$post("api/go/lists", {code: that.code}, function (_list) {
                let current_time=Date.parse(new Date())/1000;
                for(let i=0;i<_list.length;i++){
                    _list[i].endtime_str=that.setendtime_core(_list[i]['end_timestamp'],current_time)
                }
                that.golist=_list
            })
            that.$post("api/group_goods/lists", {code: that.code}, function (_list) {
                that.goods_list=_list
            })
        },
        todetail:function (id) {
            that.$router.push({path: '/pages/go/detail', query: {id: id}});
        },
        setendtime:function () {
            let current_time=Date.parse(new Date())/1000;
            //console.log(current_time)
            let list=that.golist
            for(let i=0;i<list.length;i++){
                list[i].endtime_str=that.setendtime_core(list[i]['end_timestamp'],current_time)
            }
            that.golist=list
        },
        setendtime_core:function (end_timestamp,current_time) {
            let time=end_timestamp-current_time;
            if(time<0){
                return "已结束"
            }
            let day = Math.floor(time / (60 * 60 * 24));
            let hour = Math.floor(time / (60 * 60)) - (day * 24);
            let minute = Math.floor(time / 60) - (day * 24 * 60) - (hour * 60);
            let second = Math.floor(time) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            if (day <= 9) day = '0' + day;
            if (hour <= 9) hour = '0' + hour;
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            return "剩:<span>"+day+"</span>天<span>"+hour+"</span>:<span>"+minute+"</span>:<span>"+second+"</span>"
        },
        settab:function (_tab) {
            that.tab=_tab
        }

    }
}